﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;
using System.Data;
using BusinessLogicLayer;
using DataAccessLayer;

namespace ChamCong.TaiKhoan
{
    public partial class DangNhap : System.Web.UI.Page
    {
        NhanVienBLL NVBLL = new NhanVienBLL();
        CongBLL cBLL = new CongBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        public string MaHoa(string mk)
        {
            return FormsAuthentication.HashPasswordForStoringInConfigFile(mk.Trim(), "MD5");
        }
        protected void btnDangNhap_Click(object sender, EventArgs e)
        {
            int MaNV = NVBLL.KiemTraTaiKhoan(tbxTenDangNhap.Text.Trim(), MaHoa(tbxMatKhau.Text.Trim()));
            if (MaNV > 0)
            {
                Session["MaNV"] = MaNV;
                try
                {
                    if (MaNV > 0)
                    {
                        cBLL.KiemTraTinhCong(MaNV);    
                    }
                }
                catch { }
                if (Request.QueryString["ReturnUrl"] != null)
                {
                    Response.Redirect(Request.QueryString["ReturnUrl"]);    
                }
                else
                {
                    Response.Redirect("~/NhanVien/ChamCong.aspx");    
                }
            }
            else
            {
                Response.Write("<script>alert('Tài khoản hoặc mật khẩu không đúng.');history.go(-1);</script>");
            }
        }
    }
}